#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>

/*
void *bitheart(void *arg)
{
	int ret = 0;
	int fd = *((int *)arg);

	while(1)
	{
		sleep(3);
		ret = send(fd,"heartbit",8,0);
		if(ret < 0)
		{
			perror("send");
			pthread_exit(NULL);
		}

	}
}*/


int main()
{
	int fd = 0;
	int ret = 0;
	struct sockaddr_in  addr;
	pthread_t pid = 0;

	memset(&addr,0,sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = 6868;
	addr.sin_addr.s_addr = inet_addr("192.168.0.146");

	fd = socket(AF_INET,SOCK_STREAM,0);
	if(fd < 0)
	{
		perror("socket");
		exit(-1);
	}

	ret = connect(fd,(struct sockaddr *)&addr,sizeof(struct sockaddr));
	if(ret != 0)
	{
		perror("connect");
		close(fd);
		exit(-1);
	}

/*
	ret = pthread_create(&pid,NULL,bitheart,&fd);
	if(ret != 0)
	{
		perror("pthread_create");
		exit(-1);
	}

*/


	char dest[1024] = {0};
	char buf[1024] = {0};

	while(1)
	{
		printf("please input a string:\n");
		scanf("%s",buf);

		ret = send(fd,buf,strlen(buf),0);
		if(ret <= 0)
		{
			perror("send");
			exit(-1);
		}

		printf("dest is %s\n",dest);
		memset(dest,0,sizeof(dest));

	}

	close(fd);


	return 0;

}
